<template>
  <div>
    <div><h1>交易日志</h1></div>
    <div>
      <template>
        <el-table :data="tableData" border style="width: 100%">
          <el-table-column prop="trade_id" label="订单号" width="180">
          </el-table-column>
          <el-table-column prop="publish_id" label="订单发布id" width="180">
          </el-table-column>
          <el-table-column prop="trade_quantity" label="交易量" width="80">
          </el-table-column>
          <el-table-column prop="trade_offer" label="交易单价" width="120">
          </el-table-column>
          <el-table-column prop="trade_total" label="交易额(元)" width="120">
            <template slot-scope="scope">
               {{TotalPrice(scope.row.trade_quantity,scope.row.trade_offer)}}
            </template>
          </el-table-column>
          <el-table-column prop="record_log" label="交易日志" width="360">
          </el-table-column>
          <el-table-column prop="record_hashvalue" label="哈希值"> </el-table-column>
          <el-table-column prop="sold_time" label="交易完成时间" width="180">
          </el-table-column>
        </el-table>
        <div class="pagination">
          <el-pagination
            background
            layout="total, prev, pager, next"
            :current-page="query.currentPage"
            :page-size="query.pageSize"
            :page-count="pageTotal"
            @current-change="handlePageChange"
          ></el-pagination>
        </div>
      </template>
    </div>
  </div>
</template>
    </div>
  </div>
</template>

<script>
//引入精确计算 big.js
const Big = require("big.js");

import {getTradeRecordDataByCurrentUser} from '@/api'

export default {
  name: "TradeRecordView",
  data() {
    return {
      query:{
        user_id:JSON.parse(localStorage.getItem('User')).user_id,
        currentPage: 1,
        pageSize: 10,
      },
      pageTotal: 0,
      tableData: [
        {
          record_id:1,
          trade_id:19,
          publish_id:1,
          trade_quantity:20,
          trade_offer:50.02,
          trade_total:this.trade_quantity*this.trade_offer,
          tradeuser_id:2,
          record_log:"日志内容",
          record_hashvalue:"哈希值",
          sold_time:"2024年8月27日"
        }
      ],
    };
  },
  mounted() {
    this.initData();
  },
  methods: {
    initData(){
      this.getTradeRecordDataByCurrentUser();
    },
    async getTradeRecordDataByCurrentUser(){
      let res = await getTradeRecordDataByCurrentUser(this.query);
      console.log(res)
      if(res.code == 200){
        this.tableData = res.data.data;
        this.pageTotal = res.data.pageTotal;
      }else{
        //
      }
    },
    //计算总额
    TotalPrice(counts,offer){
      let b_counts = new Big(counts);
      let b_offer = new Big(offer);
      return b_offer.times(b_counts);
    },
    // 分页导航
    handlePageChange(val) {
      // console.log(val);
      // this.$set(this.query, 'currentPage', val);
      this.query.currentPage = val;
      this.initData();
    },
  },
};
</script>

<style scoped>
</style>